package com.to_door_recycle.common.rest;

import com.to_door_recycle.common.enums.ExceptionStatusEnum;
import com.to_door_recycle.common.exception.BaseException;
import lombok.Data;

@Data
public class Response<T> {

    private Integer code;
    private T data;
    private String message;

    public Response(Integer code) {
        this.code = code;
    }

    public Response(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Response(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public Response(Integer code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> Response<T> success() {
        return new Response<T>(ExceptionStatusEnum.NOMAL.getCode());
    }

    public static <T> Response<T> success(T data) {
        return new Response<T>(ExceptionStatusEnum.NOMAL.getCode(), data);
    }

    public static <T> Response<T> success(T data, String message) {
        return new Response<T>(ExceptionStatusEnum.NOMAL.getCode(), data, message);
    }

    public static Response fail(String message) {
        return new Response(ExceptionStatusEnum.UNNORMAL.getCode(), message);
    }

    public static Response fail(String message, Integer code) {
        return new Response(code, message);
    }

    public static Response fail(BaseException e) {
        return new Response(e.getCode(), e.getMessage());
    }

    public static Response fail(ExceptionStatusEnum statusEnum) {
        return new Response(statusEnum.getCode(), statusEnum.getMessage());
    }

}
